package test7;

import java.util.*;

public class Demo13 {

    static int sum = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = "3,9,11,20,None,None,None,None,None,None,15,7,4";
        String[] arr = s.split(",");
        reverse(arr, 1, 1);
        System.out.println(sum);

    }

    static void reverse(String[] arr, int index, int level) {
        if (index > arr.length) return;

        if (level % 2 != 0 && !arr[index - 1].equals("None")) {
            int c = Integer.parseInt(arr[index - 1]);
            sum += c;
        }

        reverse(arr, 3 * index - 1, level + 1);
        reverse(arr, 3 * index, level + 1);
        reverse(arr, 3 * index + 1, level + 1);
    }

}

